package tech.aistar.day03.array;

/**
 * 本类用来演示: 自定义方法用来遍历数组
 *
 * @author: success
 * @date: 2021/3/8 4:11 下午
 */
public class PrintArrayDemo {
    public static void main(String[] args) {
        int[] arr = {10,20,30};

        //java.lang.NullPointerException空指针异常 => null.东西
        //System.out.println(arr.length);

        String result = printArr(arr);
        System.out.println(result);
    }

    public static String printArr(int[] arr){
        //判断的...
        if(null == arr || arr.length == 0){
            return "[]";
        }
        String str = "[";
        //遍历数组
       //2,3,4
        for (int i = 0; i < arr.length; i++) {
            //str+=(i!=arr.length-1)?(arr[i]+","):(arr[i]);
            if(i!=arr.length-1){
                str+=arr[i]+",";
            }else{
                str+=arr[i];
            }
        }
        str+="]";
        return str;
    }
}
